package com.tmxk.service.impl.role;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tmxk.dao.role.SysRoleMapper;
import com.tmxk.po.SysRole;
import com.tmxk.service.role.SysRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    private SysRoleMapper sysRoleMapper;

    //根据角色名称查询
    @Override
    public List<SysRole> queryAllRoleByInfo(SysRole role) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_name",role.getRoleName());
        return sysRoleMapper.selectList(queryWrapper);
    }

    @Override
    public Long selectCount(SysRole role) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_name",role.getRoleName());
        return sysRoleMapper.selectCount(queryWrapper);
    }

    @Override
    public SysRole queryRoleById(Integer roleId) {
        return sysRoleMapper.selectById(roleId);
    }

    @Override
    public int saveSysRole(SysRole role) {
        return sysRoleMapper.insert(role);
    }

    @Override
    public int deleteSysRoleById(Integer roleId) {
        return sysRoleMapper.deleteById(roleId);
    }

    @Override
    public int updateSysRole(SysRole role) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("role_id",role.getRoleId());
        return sysRoleMapper.update(role,updateWrapper);
    }
}
